package com.emagic.manage.oss.glide;

import android.content.Context;

import com.bumptech.glide.load.model.GenericLoaderFactory;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.ModelCache;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.load.model.ModelLoaderFactory;
import com.bumptech.glide.load.model.stream.BaseGlideUrlLoader;

import java.io.InputStream;

/**
 * TODO 描述该文件做什么
 *
 * @author baoy
 * @version 1.0
 *          Create by 2017/6/26 下午3:25
 */
public class OSSUrlLoader extends BaseGlideUrlLoader<OSSFile> {

    public OSSUrlLoader(ModelLoader<GlideUrl, InputStream> concreteLoader, ModelCache<OSSFile, GlideUrl> modelCache) {
        super(concreteLoader, modelCache);
    }

    @Override
    protected String getUrl(OSSFile model, int width, int height) {
        return model.buildUrl(width, height);
    }

    static class Factory implements ModelLoaderFactory<OSSFile, InputStream> {
        private final ModelCache<OSSFile, GlideUrl> modelCache = new ModelCache<>(500);

        @Override
        public ModelLoader<OSSFile, InputStream> build(Context context, GenericLoaderFactory factories) {
            return new OSSUrlLoader(factories.buildModelLoader(GlideUrl.class, InputStream.class),
                    modelCache);
        }

        @Override
        public void teardown() {
        }
    }

}
